package com.itheima.controller;

import com.itheima.po.InserClazz;
import com.itheima.po.SelectClazzParam;
import com.itheima.po.UpdateClazz;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.Log;
import com.itheima.pojo.Result;
import com.itheima.service.ClazzService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    Log log;

    @Resource
    ClazzService clazzService;

    /**
     * 获取班级分页数据
     * @param param
     * @return
     */
    @GetMapping
    public Result selectClazzPage(SelectClazzParam param){
        return clazzService.selectClazzPage(param);
    }

    /**
     * 增加班级
     */
    @PostMapping
    public Result insert(@RequestBody InserClazz clazz) {
        clazz.setCreateTime(LocalDateTime.now());
        clazz.setUpdateTime(LocalDateTime.now());
        return clazzService.insert(clazz);
    }

    /**
     * 删除班级
     */
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) {
        return clazzService.deleteById(id);
    }

    /**
     * 根据id查询班级信息
     */
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id) {
        return clazzService.selectById(id);
    }

    /**
     * 更新班级信息
     */
    @PutMapping
    public Result update(@RequestBody UpdateClazz clazz) {
        clazz.setUpdateTime(LocalDateTime.now());
        return clazzService.update(clazz);
    }

    /**
     * 查询所有班级
     */
    @GetMapping("/list")
    public Result selectAll() {
        return clazzService.selectAll();
    }

}
